//
// Created by JZYFC on 2021/11/12.
//

#include "ConsoleSettings.h"

static HANDLE hStdout;

static CONSOLE_SCREEN_BUFFER_INFO prevScreenBuffer;

bool set_console_text_color(enum COLOR color) {
    GetConsoleScreenBufferInfo(hStdout, &prevScreenBuffer);
    return SetConsoleTextAttribute(hStdout, color);
}

bool restore_prev_color() {
    return SetConsoleTextAttribute(hStdout, prevScreenBuffer.wAttributes);
}

bool clear_console() {
    return system("cls");
}

void update_stdout_handle(HANDLE mhStdout) {
    hStdout = mhStdout;
}